package com.ht.pms.core.dto;


import java.io.Serializable;

public class Result<T> implements Serializable {
    private int returnCode;
    private String codeDesc;
    private String msg;
    private T data;

    public Result() {
    }

    public static <T> Result<T> buildSuccess(T data) {
        Result<T> result = new Result();
        result.returnCode(ReturnCodeEnum.SUCCESS.getReturnCode()).codeDesc(ReturnCodeEnum.SUCCESS.getCodeDesc()).data(data);
        return result;
    }

    public static Result buildSuccess() {
        Result result = new Result();
        result.returnCode(ReturnCodeEnum.SUCCESS.getReturnCode()).codeDesc(ReturnCodeEnum.SUCCESS.getCodeDesc());
        result.setMsg(ReturnCodeEnum.SUCCESS.getCodeDesc());
        return result;
    }

    public static <T> Result<T> buildFail() {
        Result<T> result = new Result();
        result.returnCode(ReturnCodeEnum.FAIL.getReturnCode()).codeDesc(ReturnCodeEnum.FAIL.getCodeDesc());
        return result;
    }
    
    public static <T> Result<T> buildFail(String msg) {
        Result<T> result = new Result();
        result.returnCode(ReturnCodeEnum.FAIL.getReturnCode()).codeDesc(ReturnCodeEnum.FAIL.getCodeDesc());
        result.msg(msg);
        return result;
    }

    public static <T> Result<T> buildFail(String codeDesc, String msg) {
        Result<T> result = new Result();
        result.returnCode(ReturnCodeEnum.FAIL.getReturnCode()).codeDesc(ReturnCodeEnum.FAIL.getCodeDesc());
        result.codeDesc(codeDesc);
        result.msg(msg);
        return result;
    }
    public static <T> Result<T> buildParamFail(String codeDesc, String msg) {
        Result<T> result = new Result();
        result.returnCode(ReturnCodeEnum.ERROR_PARAM.getReturnCode()).codeDesc(ReturnCodeEnum.ERROR_PARAM.getCodeDesc());
        result.codeDesc(codeDesc);
        result.msg(msg);
        return result;
    }

    public static Result build(ReturnCodeEnum codeEnum) {
        Result result = new Result();
        result.returnCode(codeEnum.getReturnCode()).codeDesc(codeEnum.getCodeDesc());
        return result;
    }

    public Result<T> returnCode(int errorCode) {
        this.returnCode = errorCode;
        return this;
    }

    public Result<T> codeDesc(String codeDesc) {
        this.codeDesc = codeDesc;
        return this;
    }

    public Result<T> msg(String msg) {
        this.msg = msg;
        return this;
    }

    public Result<T> data(T data) {
        this.data = data;
        return this;
    }

    public int getReturnCode() {
        return this.returnCode;
    }

    public String getCodeDesc() {
        return this.codeDesc;
    }

    public String getMsg() {
        return this.msg;
    }

    public T getData() {
        return this.data;
    }

    public void setReturnCode(int returnCode) {
        this.returnCode = returnCode;
    }

    public void setCodeDesc(String codeDesc) {
        this.codeDesc = codeDesc;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResultWX{" +
                "returnCode=" + returnCode +
                ", codeDesc='" + codeDesc + '\'' +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
